{extend name='user/public/layout' /}
{block name='content'}
<div class="overflow_h">
    <div class="screen">
        <div class="screen_box01 overflow_h">
            <ul>
                <li><a href="{:url('user.used/index')}">二手房列表</a></li>
                <li><a href="{:url('user.used/add')}">添加二手房</a></li>
                <li><a href="{:url('user.used/message')}">二手房留言</a></li>
            </ul>
        </div>
    </div>
    <div class="user-nav">
        <form id="info_form" action="{:url('user.used/editDo')}" method="post" enctype="multipart/form-data">
            <div class="con_div">
                <ul class="formList width2 list_ul list_mp">
                    <li>
                        <label>房源名称：</label>
                        <input type="text"  name="title" id="J_title" value="{$info.title}" class="inputStyle width3">
                    </li>
                    <li>
                        <label>所属地区：</label>
                        <select name="area" id="area_id" class="selectStyle" onchange="getestate(this);" data-uri="{:url('ajaxGetEstate')}">
                            <option value="0">--请选择--</option>
                            {volist name=":cache('city')['tree']" id='vo'}
                            <option value="{$vo.id}" {if condition="$info.city eq $vo.id and $info.area eq 0"}selected{/if}>{$vo.name}</option>
                            {present name="vo['_child']"}
                            {volist name='vo["_child"]' id='val'}
                            <option value="{$val.pid},{$val.id}" {if condition="$info.area eq $val.id"}selected{/if}>--{$val.name}</option>
                            {/volist}
                            {/present}
                            {/volist}
                        </select>
                        <label class="label1">小区：</label>
                        <select name="estate_id" id="estate_id" class="selectStyle" data-uri="{:url('ajaxGetEstateInfo')}">
                            <option value="0">--请选择小区--</option>
                        </select>
                    </li>
                    <li>
                        <label>户型：</label>
                        <select name="room" id="room" class="selectStyle select1">
                            <option value="0">--室--</option>
                            {for start='1' end='8'}
                            <option value="{$i}" {if condition="$info.room eq $i"}selected{/if}>{$i}室</option>
                            {/for}
                        </select>
                        <select name="ting" id="ting" class="selectStyle select1">
                            <option value="0">--厅--</option>
                            {for start='1' end='6'}
                            <option value="{$i}" {if condition="$info.ting eq $i"}selected{/if}>{$i}厅</option>
                            {/for}
                        </select>
                        <select name="wei" id="wei" class="selectStyle select1">
                            <option value="0">--卫--</option>
                            {for start='1' end='6'}
                            <option value="{$i}" {if condition="$info.wei eq $i"}selected{/if}>{$i}卫</option>
                            {/for}
                        </select>
                        <select name="chu" id="chu" class="selectStyle select1">
                            <option value="0">--厨--</option>
                            {for start='1' end='5'}
                            <option value="{$i}" {if condition="$info.chu eq $i"}selected{/if}>{$i}厨</option>
                            {/for}
                        </select>
                        <select name="yang" id="yang" class="selectStyle select1">
                            <option value="0">--阳台--</option>
                            {for start='1' end='6'}
                            <option value="{$i}" {if condition="$info.yang eq $i"}selected{/if}>{$i}阳</option>
                            {/for}
                        </select>
                    </li>
                    <li>
                        <label>面积：</label>
                        <input type="text" class="inputStyle width2" id="mianji" value="{$info.mianji}" name="mianji" maxlength="10">
                    </li>
                    <li>
                        <label>楼层：</label>
                        <input type="text" class="inputStyle width2" name="floor" value="{$info.floor}" maxlength="10">
                        <span class="tip">共</span>
                        <input type="text" class="inputStyle width2" name="total_floor" value="{$info.total_floor}" maxlength="10">
                        <span class="tip">层</span>
                    </li>
                    <li>
                        <label>总价：</label>
                        <input type="text" class="inputStyle width2" id="total_price" value="{$info.total_price}" name="total_price" maxlength="10">
                        <span class="tip">万</span>
                        <label class="label1">均价：</label>
                        <input type="text" class="inputStyle width2" id="price" name="price" value="{$info.price}" maxlength="10">
                        <span class="tip">元/平米</span>
                    </li>
                    <li class="li_checkbox" id="used_type"><label class="lw90">楼盘类型：</label>{:getLinkMenu(7,'house_type','checkbox',explode(',',$info['house_type']))}</li>
                    <li class="li_radio"><label class="lw90">装修情况：</label>{:getLinkMenu(9,'zhuangxiu','radio',$info['zhuangxiu'])}</li>
                    <li class="li_radio"><label class="lw90">朝向：</label>{:getLinkMenu(12,'chaoxiang','radio',$info['chaoxiang'])}</li>
                    <li class="li_checkbox"><label class="lw90">房屋配套：</label>{:getLinkMenu(13,'peitao','checkbox',explode(',',$info['peitao']))}</li>
                    <li>
                        <label>建筑年代：</label>
                        <input type="text" class="inputStyle width2" id="niandai" value="{$info.niandai}" name="niandai" maxlength="10">
                        <span class="tip">年</span>
                    </li>
                    <li>
                        <label>所在地址：</label>
                        <input type="text" class="inputStyle width3" id="address" value="{$info.address}" name="address">
                        <span class="tip">中文字符</span>
                    </li>
                    <li>
                        <label>地图标注：</label>
                        <input type="text" class="inputStyle" id="map" name="map" value="{$info.lng},{$info.lat}">
                        <span class="tip"><a target="_blank" class="but19" href="http://api.map.baidu.com/lbsapi/getpoint/">获取百度地图坐标</a></span>
                    </li>
                    <li id="files">
                        <label>多图上传：</label>
                        <script id="uploadpic" name="uploadpic" type="text/plain"></script>
                        <input type="button" class="btn btn_submit" style="margin:0 0 10px 10px;" onclick="upImage();" value="选择图片">
                        <div id="imageList">
                            <ul class="list clearfix">
                                {volist name='info.file' id='vo'}
                                <li>
                                    <img width="115" height="115" alt="{$vo.title}" src="{$vo.url}">
                                    <input type="hidden" value="{$vo.url}" name="pic[pic][]">
                                    <input type="text" class="imgtitletxt" value="{$vo.title}" name="pic[alt][]">
                                    <div class="delbox"><span onclick="delImg(this)" class="del">删除</span></div>
                                </li>
                                {/volist}
                            </ul>
                        </div>
                        <input type="hidden" name="file" id="file" />
                    </li>
                    <li style="height:auto;">

                        <label>缩例图：</label><input type="file" name="img">
                        {notempty name='info.img'}

                        <p style="padding-left:90px;"><img src="{$info.img}" alt="" width="100"></p>

                        {/notempty}
                    </li>
                    <li class="height1"><label>特色：</label><textarea class="textarea" style="width: 550px;float: left" id="tags" name="tese">{$info.tese}</textarea></li>
                    <li>
                        <label>联系人 ：</label>
                        <input type="text" class="inputStyle width1" id="contact" value="{$info.contact}" name="contact">
                    </li>
                    <li>
                        <label>联系电话：</label>
                        <input type="text" class="inputStyle width1" id="contact_phone" value="{$info.contact_phone}" name="contact_phone">
                    </li>
                    <li>
                        <label>急售房源：</label>
                        <input type="radio" name="jishou" id="jishou_1" value="1" {if condition="$info.jishou eq 1"}checked{/if} />是
                        <input type="radio" name="jishou" id="jishou_0" value="0" {if condition="$info.jishou eq 0"}checked{/if}/>否
                    </li>
                    <li>
                        <label>发布状态：</label>
                        {if condition='$info.status eq  1 or $info.status eq 3'}
                        <input type="radio" name="status" id="status_1" value="1" {if condition="$info.status eq 1"}checked{/if} />发布
                        <input type="radio" name="status" id="status_0" value="3" {if condition="$info.jishou eq 3"}checked{/if}/>草稿
                        {else /}
                        {:optionStatus($info['status'])}
                        {/if}
                    </li>
                    <li style="margin-bottom: 5px;"><label>房源介绍：</label><label style="width: 400px;"><input type="checkbox" name="thumb" value="1"> 使用内容第一张图片做为缩例图</label></li>
                    <li class="height2">
                        <textarea name="info" id="info">{$info.info}</textarea>
                    </li>
                    <input type="hidden" name="estate_name" value="{$info.estate_name}" id="estate_name">
                    <input type="hidden" name="id" value="{$info.id}">
                    <li>
                        <label></label>
                        <input type="submit" value="提 交" class="btnStyle" onclick="window.scroll(0,0);">
                    </li>
                </ul>
            </div>
        </form>
    </div>
</div>
<script src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
<script src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
<script src="__PUBLIC__/js/ueditor/lang/zh-cn/zh-cn.js"></script>
<script src="__PUBLIC__/js/ueditor/uploadImg.js"></script>
<script src="__PUBLIC__/js/plugins/formvalidator.js"></script>
<script type="text/javascript">
    window.UEDITOR_HOME_URL='__PUBLIC__/js/ueditor/';
    window.onload=function(){
        window.UEDITOR_CONFIG.initialFrameWidth=880;
        window.UEDITOR_CONFIG.initialFrameHeight=500;
        window.UEDITOR_CONFIG.autoHeightEnabled = false;
        var ue = UE.getEditor('info', {
            toolbars: [[
                'fullscreen', 'source', '|',
                'bold', 'italic', 'underline', '|', 'fontfamily','fontsize', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', 'insertimage','|', 'kityformula', 'preview'
            ]]
        });
        upmoreimg();
    };
    getestate(document.getElementById('area_id'));
    $(function(){
        $.formValidator.initConfig({formid:"info_form",autotip:true});
        $("#area_id").formValidator({onshow:"请选择区域",onfocus:"请选择区域"}).inputValidator({min:1,onerror:"请选择区域"}).defaultPassed();
        $("#J_title").formValidator({onshow:"请填写房源名称",onfocus:"请填写房源名称"}).inputValidator({min:1,onerror:"请填写房源名称"}).defaultPassed();
        $("#mianji").formValidator({onshow:"请填写面积",onfocus:"请填写面积"}).regexValidator({regexp:"num",datatype:"enum",onerror:"面积只能为数字"}).defaultPassed();
        $("#total_price").formValidator({onshow:"请填写总价",onfocus:"请填写总价"}).regexValidator({regexp:"num",datatype:"enum",onerror:"总价只能为数字"}).defaultPassed();
        $("#price").formValidator({onshow:"请填写单价",onfocus:"请填写单价"}).regexValidator({regexp:"num",datatype:"enum",onerror:"单价只能为数字"}).defaultPassed();
        $("#niandai").formValidator({onshow:"请填写建筑年代",onfocus:"请填写建筑年代"}).regexValidator({regexp:"num",datatype:"enum",onerror:"建筑年代只能为数字"}).defaultPassed();
        $("#contact").formValidator({onshow:"请填写联系人",onfocus:"请填写联系人"}).inputValidator({min:1,onerror:"请填写联系人"}).defaultPassed();
        $("#contact_phone").formValidator({onshow:"请填写联系电话",onfocus:"请填写联系电话"}).inputValidator({min:7,onerror:"联系电话格式不正确"}).defaultPassed();

        $(":radio[name^='zhuangxiu']").formValidator({onshow:"请选择装修情况",onfocus:"请选择装修情况"}).inputValidator({min:1,max:10,onerror:"请选择装修情况"}).defaultPassed();
        $(":radio[name^='chaoxiang']").formValidator({onshow:"请选择朝向",onfocus:"请选择朝向"}).inputValidator({min:1,max:10,onerror:"请选择朝向"}).defaultPassed();
        $(":checkbox[name^='house_type']").formValidator({onshow:"请选择楼盘类型",onfocus:"你至少选择1项"}).inputValidator({min:1,max:10,onerror:"请至少选择一项"}).defaultPassed();
        $("#estate_id").bind('change',function(){
            var url = $(this).data('uri'),id = $(this).val();
            var param = {id:id};
            $.get(url,param,function(res){
                if(res.status == 1){
                    $('#niandai').val(res.data.niandai);
                    $('#address').val(res.data.address);
                    $('#map').val(res.data.map);
                    $('#estate_name').val(res.data.title);
                }
            });
        });
    });
    function getestate(o){
        var id = $(o).val(),url = $(o).data('uri'),param={area_id:id},estate_id="{$info.estate_id}";
        $.get(url,param,function(res){
            var str = '<option value="0">--请选择小区--</option>';
            if(res.status == 1){
                var data  = res.data,select='';
                for(var i in data){
                    if(estate_id == data[i]['id']){
                        select = 'selected';
                    }
                    str += "<option value='"+data[i]['id']+"' "+select+">"+data[i]['title']+"</option>";
                }
                $('#estate_id').html(str);
            }else{
                $('#estate_id').html(str);
            }
        });
    }
</script>
{/block}